﻿using System;
using System.Windows.Forms;
using Relocation.Com.Tools;
using Relocation.Base;
using Relocation.Data;
using Relocation.Com;


namespace Relocation.UI
{
	public partial class ProjectSelect : BaseProjectList
	{	
		/// <summary>
		/// 用户选中的Project对象
		/// </summary>
		public Project Project
		{
			get;private set;
		}
		
		public ProjectSelect(Session session)
			: base(session)
		{
			InitializeComponent();
			//this.SortField = "updated";
			this.ObjectQuery = this.Session.DataModel.Projects;
		}
				
		/// <summary>
		/// 选择项目
		/// </summary>		
		private void pro_main_ok_bt_Click(object sender, EventArgs e)
		{
			try
			{
				this.Project= this.GetSelectEntity();
				if (this.Project == null)
					return;
				this.DialogResult = DialogResult.OK;
				this.Close();
			} catch (Exception ex)
			{
				Log.Error(ex.Message);
				MyMessagebox.Error(ex.Message);
			}
		}

		/// <summary>
		/// 取消按钮，关闭该form
		/// </summary>		
		private void pro_main_cancle_bt_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		/// <summary>
		/// 禁止双击窗口标题栏时窗口变大变小
		/// </summary>		
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == 0xa3)
			{
				return;
			}
			base.WndProc(ref m);
		}		

		protected override void DataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{			
			this.pro_main_ok_bt.PerformClick();
		}

		private void projectsMainDataGridView_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode.Equals(Keys.Enter))
				this.pro_main_ok_bt.PerformClick();
		}
		
	}
}
